home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Concept 6
/
CD Concept 06.iso
/
mac
/
UTILITAIRE
/
RLaB
/
rlib
/
cumprod.r
< prev
next >
Wrap
Text File
|
1994-09-23
|
697b
|
40 lines
//-------------------------------------------------------------------//
// Syntax: cumprod ( X )
// Description:
// Compute the cumulative product of a vector or a matrix.
// See Also: prod
//-------------------------------------------------------------------//
cumprod = function ( x )
{
m = x.nr;
n = x.nc;
new = zeros (m, n);
if (min ([m, n]) == 1)
{
// cumsum on a vector
new[1] = x[1];
for (i in 2:max ([m,n]))
{
new[i] = x[i] * new[i-1];
}
else
// cumsum on the columns of a matrix
for (i in 1:n)
{
new[1;i] = x[1;i];
for (j in 2:m)
{
new[j;i] = x[j;i] * new[j-1;i];
}
}
}
return (new);
};